home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / ebksrc / eb4.cpp < prev    next >
C/C++ Source or Header  |  1995-11-01  |  7KB  |  335 lines

  1. /*
  2.  
  3.     eb4.cpp
  4.     7-31-91
  5.     Electronic Book
  6.  
  7.  
  8.     Copyright 1991
  9.     John W. Small
  10.     All rights reserved
  11.  
  12.     Licensed users of FlexList may use and modify this
  13.     tool for use in their programs.
  14.  
  15.  
  16.     PSW / Power SoftWare
  17.     P.O. Box 10072
  18.     McLean, Virginia 22102 8072 USA
  19.  
  20.     Voice: (703) 759-3838
  21.     CIS: 73757,2233
  22.  
  23.  
  24.     Notes:  The Electronic Book was coded to demonstrate
  25.     the various uses of FlexList.
  26.  
  27.  
  28. */
  29.  
  30. #include <process.h>
  31. #include <ctype.h>
  32. #include <eb4.hpp>
  33.  
  34. #ifndef PICKFILE_HPP
  35. #include <pickfile.hpp>
  36. #endif
  37.  
  38. #ifndef PCKEY_HPP
  39. #include <pckey.hpp>
  40. #endif
  41.  
  42.  
  43.  
  44.  
  45. Arguments::Arguments(const char *A) : FlexList(FLstrings)
  46. {
  47.     int i, j, l;
  48.  
  49.     V = (char **)0;
  50.     if (!A)
  51.         return;
  52.     for (i = j = 0; A[i] && i < MAX_HYPER_LINE; i = j) {
  53.         while (isspace(A[i]))
  54.             i++;
  55.         for (j = i; A[j] && !isspace(A[j]); j++)
  56.             /* null stmt */;
  57.         if (j > i && (l = (j-i)) < MAX_ARG_LEN)  {
  58.             strncpy(buf,&A[i],l);
  59.             buf[l] = '\0';
  60.             insQD(buf);
  61.         }
  62.     }
  63.     V = (char **) packPtrs();
  64. }
  65.  
  66.  
  67. Palette HVTWdefaultP = {
  68.  
  69.     0,  /*  monochrome         or         color  */
  70.  
  71.     svideo(DARKGRAY,LIGHTGRAY),    svideo(LIGHTRED,BLUE),
  72.     svideo(WHITE,LIGHTGRAY),    svideo(LIGHTRED,BLUE),
  73.     svideo(WHITE,LIGHTGRAY),    svideo(LIGHTRED,BLUE),
  74.     svideo(DARKGRAY,BLACK),        svideo(CYAN,BLUE),
  75.     svideo(BLACK,LIGHTGRAY),    svideo(WHITE,BLUE),
  76.     svideo(WHITE,LIGHTGRAY),    svideo(LIGHTGRAY,RED),
  77.     svideo(WHITE,BLACK),        svideo(WHITE,BLUE)
  78. };
  79.  
  80.  
  81. int HyperView::view(const char * hyperFname,
  82.     const char * topic, int l, int t, int r, int b)
  83. {
  84.     struct text_info ti;
  85.     TextWindow TW(HVTWdefaultP);
  86.     PickFile pf;
  87.     TargetParser tp;
  88.     ArgumentS A;
  89.     enum HC_ACTIONS hca;
  90.     int backTrack;
  91.     int fullScreen = 0;
  92.  
  93.     if (l < 1)
  94.         fullScreen = 1;
  95.     if (fullScreen)  {
  96.         gettextinfo(&ti);
  97.         l = t = 1;
  98.         r = ti.screenwidth;
  99.         b = ti.screenheight;
  100.     }
  101.     if (fullScreen)
  102.         TW.window(l,t,r,b,DOUBLE_FRAME,0,1,0);
  103.     else
  104.         TW.window(l,t,r,b);
  105.     if (hyperFname)  {
  106.         hstk.pushTarget(hyperFname,topic);
  107.         backTrack = 0;
  108.     }
  109.     else
  110.         backTrack = 1;
  111.     while (1)  {
  112.         if (!hstk.targets())
  113.             if (pf.choose((char *)0,FA_DIREC,".htx"))  {
  114.                 hstk.pushTarget(pf.choice());
  115.                 backTrack = 0;
  116.             }
  117.             else  {
  118.                 TW.close();
  119.                 return -1;
  120.             }
  121.         if ((HC = hser.fetch(hstk.topTarget(),
  122.             backTrack)) == HyperContexT0)  {
  123.             hstk.popTarget();
  124.             backTrack = 1;
  125.             continue;
  126.         }
  127.         while (HC)  {
  128.         hca = HC->view();
  129.         hstk.setTopView(HC->StartColumn(),HC->StartRow(),
  130.             HC->CursorColumn(),HC->CursorRow());
  131.         switch (hca)  {
  132.         case HyperContext::HELP:
  133.             help();
  134.             break;
  135.         case HyperContext::LOAD:
  136.             if (pf.choose((char *)0,FA_DIREC,".htx"))
  137.                 if (hstk.pushTarget(pf.choice()))  {
  138.                     delete TOC;
  139.                     delete IDX;
  140.                     TOC = PickTOC0;
  141.                     IDX = PickIDX0;
  142.                     delete HC;
  143.                     HC = HyperContexT0;
  144.                     backTrack = 0;
  145.                 }
  146.             break;
  147.         case HyperContext::TABLE_OF_CONTENTS:
  148.             if (!TOC) TOC = hser.TableOfContents
  149.                 (hstk.topFname());
  150.             if (TOC) if (TOC->choose(HC->TopicNum()))
  151.             if (hstk.pushTarget(hstk.topFname(),
  152.                 TOC->choice())) {
  153.                 delete HC;
  154.                 HC = HyperContexT0;
  155.                 backTrack = 0;
  156.             }
  157.             break;
  158.         case HyperContext::INDEX:
  159.             if (!IDX) IDX = hser.Index(hstk.topFname());
  160.             if (IDX) if (IDX->choose())
  161.             if (hstk.pushTarget(hstk.topFname(),
  162.                 IDX->choice())) {
  163.                 delete HC;
  164.                 HC = HyperContexT0;
  165.                 backTrack = 0;
  166.             }
  167.             break;
  168.         case HyperContext::LAUNCH:
  169.             switch (tp.parse(HC->newTarget()))  {
  170.             case TargetParser::UNKNOWN:
  171.                 break;
  172.             case TargetParser::NEAR_TOPIC:
  173.             case TargetParser::NEAR_DEFAULT:
  174.                 if (hstk.pushTarget(hstk.topFname(),
  175.                     tp.topic())) {
  176.                     delete HC;
  177.                     HC = HyperContexT0;
  178.                     backTrack = 0;
  179.                 }
  180.                 break;
  181.             case TargetParser::FAR_TOPIC:
  182.             case TargetParser::FAR_DEFAULT:
  183.                 if (hstk.pushTarget(tp.params(),
  184.                     tp.topic())) {
  185.                     delete TOC;
  186.                     delete IDX;
  187.                     TOC = PickTOC0;
  188.                     IDX = PickIDX0;
  189.                     delete HC;
  190.                     HC = HyperContexT0;
  191.                     backTrack = 0;
  192.                 }
  193.                 break;
  194.             case TargetParser::FAR_SYSTEM:
  195.                 delete TOC;
  196.                 delete IDX;
  197.                 TOC = PickTOC0;
  198.                 IDX = PickIDX0;
  199.                 delete HC;
  200.                 HC = HyperContexT0;
  201.                 TW.close();
  202.                 textattr(LIGHTGRAY+BLACK*16);
  203.                 clrscr();
  204.                 system(tp.params());
  205.                 cputs("Press any key ...");
  206.                 getch();
  207.                 backTrack = 1;
  208.                 if (fullScreen)  {
  209.                     gettextinfo(&ti);
  210.                     l = t = 1;
  211.                     r = ti.screenwidth;
  212.                     b = ti.screenheight;
  213.                 }
  214.                 if (fullScreen)
  215.                     TW.window(l,t,r,b,DOUBLE_FRAME,0,1,0);
  216.                 else
  217.                     TW.window(l,t,r,b);
  218.                 break;
  219.             case TargetParser::FAR_SPAWN:
  220.                 if ((A = new Arguments(tp.params()))
  221.                     == ArgumentS0)
  222.                     break;
  223.                 if (!A->argc())  {
  224.                     delete A;
  225.                     break;
  226.                 }
  227.                 delete TOC;
  228.                 delete IDX;
  229.                 TOC = PickTOC0;
  230.                 IDX = PickIDX0;
  231.                 delete HC;
  232.                 HC = HyperContexT0;
  233.                 TW.close();
  234.                 textattr(LIGHTGRAY+BLACK*16);
  235.                 clrscr();
  236.                 spawnvp(P_WAIT,A->argv0(),A->argv());
  237.                 delete A;
  238.                 backTrack = 1;
  239.                 if (fullScreen)  {
  240.                     gettextinfo(&ti);
  241.                     l = t = 1;
  242.                     r = ti.screenwidth;
  243.                     b = ti.screenheight;
  244.                 }
  245.                 if (fullScreen)
  246.                     TW.window(l,t,r,b,DOUBLE_FRAME,0,1,0);
  247.                 else
  248.                     TW.window(l,t,r,b);
  249.                 break;
  250.             }
  251.             break;
  252.         case HyperContext::BACKUP:
  253.             if (hstk.targets() > 1)  {
  254.                 delete TOC;
  255.                 delete IDX;
  256.                 TOC = PickTOC0;
  257.                 IDX = PickIDX0;
  258.                 delete HC;
  259.                 HC = HyperContexT0;
  260.                 hser.discard(hstk.topFname());
  261.                 hstk.popTarget();
  262.                 backTrack = 1;
  263.             }
  264.             break;
  265.         case HyperContext::EXIT:
  266.             delete TOC;
  267.             delete IDX;
  268.             TOC = PickTOC0;
  269.             IDX = PickIDX0;
  270.             delete HC;
  271.             HC = HyperContexT0;
  272.             TW.close();
  273.             return 0;
  274.         case HyperContext::ATTR_TOGGLE:
  275.             TW.close();
  276.             forcedmonochrome = !forcedmonochrome;
  277.             if (fullScreen)
  278.                 TW.window(l,t,r,b,
  279.                     DOUBLE_FRAME,0,1,0);
  280.             else
  281.                 TW.window(l,t,r,b);
  282.             break;
  283.         case HyperContext::RES_TOGGLE:
  284.             TW.close();
  285.             toggleRes();
  286.             PCF.reset();
  287.             if (fullScreen)  {
  288.                 gettextinfo(&ti);
  289.                 l = t = 1;
  290.                 r = ti.screenwidth;
  291.                 b = ti.screenheight;
  292.             }
  293.             if (fullScreen)
  294.                 TW.window(l,t,r,b,
  295.                     DOUBLE_FRAME,0,1,0);
  296.             else
  297.                 TW.window(l,t,r,b);
  298.             break;
  299.  
  300.         } // switch (hca)
  301.         } // while (HC)
  302.     }  // while (1)
  303.     TW.close();
  304.     return -1;
  305. }
  306.  
  307. void HyperView::help()
  308. {
  309.     TextWindow TW;
  310.  
  311.     TW.window(10,5,70,19);
  312.     TW.putTitle(" EB Help ");
  313.     cputs("\n\r      F1                  Help"
  314.           "\n\r      F3                  Load new HyperText file"
  315.           "\n\r      F10, AltT           Table of Contents"
  316.           "\n\r      AltF10, AltI        Index"
  317.           "\n\r      CR                  Tranverse HyperLink"
  318.           "\n\r      AltF1, BACKSP       Backtrack HyperLink"
  319.           "\n\r      F6                  Toggle 25 - 43/50 lines"
  320.           "\n\r      ShiftF6             Toggle monochrome/color"
  321.           "\n\r      AltX                Exit"
  322.           "\n\n\r      Your choice ...");
  323.     while (!PCK.kbhit()) /* null stmt */;
  324.     TW.close();
  325. }
  326.  
  327. HyperView::~HyperView()
  328. {
  329.     delete HC; delete TOC; delete IDX;
  330.     while (hstk.targets()) {
  331.         hser.discard(hstk.topFname());
  332.         hstk.popTarget();
  333.     }
  334. }
  335.